package com.mgface.framework.condition;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class WindowsPlatformCondition implements Condition {
	private final static Logger log = LogManager.getLogger(WindowsPlatformCondition.class);

	@Override
	public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
		String osname = context.getEnvironment().getProperty("os.name");
		boolean flag = osname.toLowerCase().contains("windows");
		if (flag) {
			log.info("应用的部署平台为:{},标注@Conditional({})的类满足Bean创建条件", osname,WindowsPlatformCondition.class.getSimpleName());
		} else {
			log.info("应用的部署平台为:{},标注@Conditional({})的类不满足Bean创建条件,Bean创建失败", osname,WindowsPlatformCondition.class.getSimpleName());
		}
		return flag;
	}
}
